GtkThemingEngine: use background-image in render_background()
authorCarlos Garnacho <carlosg@gnome.org>
Thu, 2 Sep 2010 00:14:10 +0000 (02:14 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Sat, 4 Dec 2010 14:38:12 +0000 (15:38 +0100)
gtk/gtkthemingengine.c

index b37a3885648aa1f4e8550b04ca411a76a5c93625..5a2285aad774aa4af60fadf181fe5c2fb067f0f5 100644 (file)
@@ -892,28 +892,47 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
                                       gdouble           width,
                                       gdouble           height)
 {
+  GdkColor *bg_color, *base_color;
+  cairo_pattern_t *pattern;
   GtkStateFlags flags;
-  GdkColor *color;
 
-  cairo_save (cr);
   flags = gtk_theming_engine_get_state (engine);
-
-  if (gtk_theming_engine_has_class (engine, "entry"))
-    gtk_theming_engine_get (engine, flags,
-                            "base-color", &color,
-                            NULL);
-  else
-    gtk_theming_engine_get (engine, flags,
-                            "background-color", &color,
-                            NULL);
-
-  gdk_cairo_set_source_color (cr, color);
+  cairo_save (cr);
 
   if (gtk_theming_engine_has_class (engine, "spinbutton") &&
       gtk_theming_engine_has_class (engine, "button"))
-    cairo_rectangle (cr, x + 2, y + 2, width - 4, height - 4);
+    {
+      x += 2;
+      y += 2;
+      width -= 4;
+      height -= 4;
+    }
+
+  gtk_theming_engine_get (engine, flags,
+                          "background-image", &pattern,
+                          "background-color", &bg_color,
+                          "base-color", &base_color,
+                          NULL);
+
+  if (pattern)
+    {
+      cairo_translate (cr, x, y);
+      cairo_scale (cr, width, height);
+
+      cairo_rectangle (cr, 0, 0, 1, 1);
+      cairo_set_source (cr, pattern);
+
+      cairo_pattern_destroy (pattern);
+    }
   else
-    cairo_rectangle (cr, x, y, width, height);
+    {
+      if (gtk_theming_engine_has_class (engine, "entry"))
+        gdk_cairo_set_source_color (cr, base_color);
+      else
+        gdk_cairo_set_source_color (cr, bg_color);
+
+      cairo_rectangle (cr, x, y, width, height);
+    }
 
   if (gtk_theming_engine_has_class (engine, "tooltip"))
     {
@@ -927,7 +946,8 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
 
   cairo_restore (cr);
 
-  gdk_color_free (color);
+  gdk_color_free (base_color);
+  gdk_color_free (bg_color);
 }
 
 static void